// pages/find-exhibits/find-exhibits.js
var common = require("../../utils/util.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
     data:[],
     pageSize:10,
     page:1,
     refresh: true
  },
  /**
   * 生命周期函数--监听页面加载
   */
  goodsDetail: function (e) {
    
    var that = this
    that.setData({
      ProductID: e.currentTarget.dataset.id
    })
    
    wx.navigateTo({
      url: '../goodsDetail/goodsDetail?goodsId=' + that.data.ProductID
    })
  },
  onLoad: function (options) {
    //ajax
    var that = this
    common.ajax({
      url: 'PersonMain/GetMicroProductInfoList',
      data:{
        pageIndex: that.data.page,
        pageSize: that.data.pageSize,
        searchStr:'',
        pdtIDs:''
      },
      loading: '',
      userinfo: false,
      success: function (res) {
        if (res.message != 'success') {
          console.log(1)
       } else {
          that.setData({
            data: res.data,
            page: 2
          })
          console.log(res.data)
        }
      }
    })
    //ajax
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
    if (that.data.refresh) {
    //ajax
    
    common.ajax({
      url: 'PersonMain/GetMicroProductInfoList',
      data: {
        pageIndex: that.data.page,
        pageSize: that.data.pageSize,
        searchStr: '',
        pdtIDs: ''
      },
      loading: '',
      userinfo: false,
      success: function (res) {
        if (res.message != 'success') {
          console.log(1)
        } else {
          if (res.data == null){
             return false
          }
          if (res.data.length > 0) {
            console.log(res.data)
            that.data.data = that.data.data.concat(res.data)
            that.setData({
              data: that.data.data,
              page: that.data.page++
            })
          } 
          console.log(res.data.length)
          if (res.data.length < that.data.pageSize) {
            that.setData({
              refresh: false
            })
          } else {
            console.log(999)
            that.data.page ++
            that.setData({
              page: that.data.page
            })
           
            console.log(that.data.page)
          }
        }
      }
    })
    //ajax
  }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})